﻿using System;
using System.Collections.Generic;
using System.Text;
using Mogre;
using MogreNewt;
using MogreNewt.CollisionPrimitives;

namespace AplikacjaOgre
{
    class Terrain
    {
        #region Definiowanie zmiennych

        Entity Graphics;
        SceneNode GraphicsNode;

        Entity Collision;
        SceneNode CollisionNode;

        Body Body;

        #endregion

        #region Funkcje tworzące sieci wyglądu planszy i kolizji planszy

        public void setGraphicsMesh(String MeshFileName)
        {
            GraphicsNode = Game.Instance.SceneManager.RootSceneNode.CreateChildSceneNode();
            Graphics = Game.Instance.SceneManager.CreateEntity(MeshFileName);
            GraphicsNode.SetScale(new Vector3(2.5f,2.5f,2.5f));
            
            GraphicsNode.AttachObject(Graphics);
            Graphics.CastShadows = false;
        }

        public void setCollisonMesh(String MeshFileName)
        {
            CollisionNode = Game.Instance.SceneManager.RootSceneNode.CreateChildSceneNode();
            Collision = Game.Instance.SceneManager.CreateEntity(MeshFileName);
            CollisionNode.SetScale(new Vector3(2.5f, 2.5f, 2.5f));

            CollisionNode.AttachObject(Collision);
            CollisionNode.SetVisible(false);

            TreeCollisionSceneParser collisionParser = new TreeCollisionSceneParser(Game.Instance.NewtonWorld);
            collisionParser.ParseScene(CollisionNode, true, 1);

            Body = new Body(Game.Instance.NewtonWorld, collisionParser);
            collisionParser.Dispose();

            Body.AttachNode(CollisionNode);
        }

        #endregion
    }
}
